package com.sangeng.controller;


import com.sangeng.domain.core.ResponseResult;
import com.sangeng.domain.dto.ArticleListDto;
import com.sangeng.domain.entity.Article;
import com.sangeng.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "文章管理")
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @ApiOperation("查询所有文章")
    @GetMapping("/list")
    public ResponseResult list(){
        return ResponseResult.okResult(articleService.list());
    }

    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){
        return articleService.hotArticleList();
    }

    @GetMapping("/articleList")
    public ResponseResult articleList(ArticleListDto articleListDto){
        return articleService.articleList(articleListDto);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleDetialsById(@PathVariable Long id){
        return articleService.getArticleDetialsById(id);
    }

    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable Long id){
        return articleService.updateViewCount(id);
    }
}
